<?php
App::uses('ArticlesFactory', 'Model');
App::uses('RssComponent', 'Controller/Component');
App::uses('ComponentCollection', 'Controller');
class ArticlesFactoryTest extends CakeTestCase{

	public function setUp(){
		parent::setUp();
		$collection = new ComponentCollection();
		$this->ArticlesFactory = new ArticlesFactory($collection);
		$this->RssComponent = new RssComponent($collection);
	}

	public function testCreateInRssVer1(){
		// fetch RSS
		$url = "http://itpro.nikkeibp.co.jp/rss/ittrend.rdf";//it's RSS 1.0
		$rss = $this->RssComponent->parse($url);
		//create Articles 	
		$articles = $this->ArticlesFactory->create($rss);	
		//assert
		$this->assertNotEmpty($articles);
		foreach($articles as $article){
			$this->assertArrayHasKey('link', $article);
			$this->assertArrayHasKey('title', $article);
			$this->assertArrayHasKey('description', $article);
		}
	}

	public function testCreateInRssVer2(){
		//fetch RSS
		$url = "http://rss.rssad.jp/rss/itmatmarkit/rss.xml";//it's RSS 2.0
		$rss = $this->RssComponent->parse($url);
		//create Articles 	
		$articles = $this->ArticlesFactory->create($rss);	
		//assert
		$this->assertNotEmpty($articles);
		foreach($articles as $article){
			$this->assertArrayHasKey('link', $article);
			$this->assertArrayHasKey('title', $article);
			$this->assertArrayHasKey('description', $article);
		}
	}

}

?>
